package org.wltea.analyzer.dic;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 词典加载器工厂
 * @author jl_zhuang
 * 2019/7/18 0018
 */
public class DictionaryLoaderFactory {

    private static Map<String, DictionaryLoader> dictionaryLoaderMap = new HashMap<String, DictionaryLoader>(1);

    private static List<String> loaderNameEnableList = new ArrayList<String>(1);

    public static final String defaultLoaderName = "main";

    static {
        loaderNameEnableList.add(defaultLoaderName);
        dictionaryLoaderMap.put(defaultLoaderName, new DefaultDictionaryLoader());
    }

    /**
     * 设置启用加载器列表
     * @param loaderNameEnableList
     */
    public static void setEnableLoaderName(List<String> loaderNameEnableList){
        DictionaryLoaderFactory.loaderNameEnableList = loaderNameEnableList;
    }

    /**
     * 添加启用加载器
     * @param name
     */
    public static void addEnableLoaderName(String name){
        loaderNameEnableList.add(name);
    }

    /**
     * 添加加载器
     * @param loaderName
     * @param dictionaryLoader
     */
    public static void addDictionaryLoader(String loaderName, DictionaryLoader dictionaryLoader){
        dictionaryLoaderMap.put(loaderName, dictionaryLoader);
    }

    /**
     * 获取加载器
     * @return
     */
    public static List<DictionaryLoader> getDictionaryLoader(){
        List<DictionaryLoader> loaders = new ArrayList<DictionaryLoader>();
        for(String name:loaderNameEnableList){
            loaders.add(dictionaryLoaderMap.get(name));
        }
        return loaders;
    }

}
